import 'package:bruno/bruno.dart';

class BrnRowDelegate  extends BrnMultiDataPickerDelegate{

  int firstSelectedIndex = 0;
  int secondSelectedIndex = 0;
  int thirdSelectedIndex = 0;

  late List<dynamic> list;

  int columnNum = 0;


  BrnRowDelegate({
    this.firstSelectedIndex = 0,
    this.secondSelectedIndex = 0,
    this.columnNum = 1,
    required this.list
  });

  @override
  int initSelectedRowForComponent(int component) {
    if (0 == component) {
      return firstSelectedIndex;
    }
    return 0;
  }

  @override
  int numberOfComponent() {
    return columnNum;
  }

  @override
  int numberOfRowsInComponent(int component) {
    if (0 == component) {
      return list.length;
    } else if(1 == component && list[firstSelectedIndex]['children'] != null){
      return list[firstSelectedIndex]['children'].length;
    }
    return 0;
  }

  @override
  double? rowHeightForComponent(int component) {
    return null;
  }

  @override
  void selectRowInComponent(int component, int row) {
    if (0 == component) {
      firstSelectedIndex = row;
    } else if (1 == component) {
      secondSelectedIndex = row;
    } else {
      thirdSelectedIndex = row;
      print('_thirdSelectedIndex  is selected to $thirdSelectedIndex');
    }
  }

  @override
  String titleForRowInComponent(int component, int index) {
    if (0 == component) {
      Map<String, dynamic> secondMap = list[index];
      return secondMap['name'];
    } else if(1 == component && list[firstSelectedIndex]['children'] != null){
      Map<String, dynamic> secondMap = list[firstSelectedIndex];
      List<dynamic> children = secondMap['children'];
      return children[index]['name'];
    }
    return "";
  }
  
}